﻿using System;
using System.Collections.Generic;
using System.Collections.ObjectModel;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using metroCIS.Library;

namespace metroCIS.ViewModel
{
    public class OverviewViewModel : ViewModelBase
    {
        public ObservableCollection<RssItem> RssItems { get; private set; }
        public LvEntry NextLesson { get { return _nextLesson; } set { _nextLesson = value; OnPropertyChanged("NextLesson"); } }
        private LvEntry _nextLesson;

        public OverviewViewModel()
        {
            RssItems = new ObservableCollection<RssItem>();
            Refresh();
        }

        private async void Refresh()
        {
            var manager = CisManager.Create();
            var lessons = await manager.GetLVPlan();
            NextLesson = lessons.FirstOrDefault();
            RssItems.Clear();
            foreach (var rssItem in await manager.GetRssFeed())
                RssItems.Add(rssItem);
        }
    }
}
